<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML >
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>添加课程表</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	
    <%@include file="/pages/head/head.jsp" %>
     
  </head>
  
  <body>
   <div id="wrapper">
        <!-- 左边菜单 -->
         <%@include file="/pages/left/leftmenu.jsp" %>

        <div id="page-wrapper" class="gray-bg dashbard-1">
             <!-- 引入top菜单 -->
              <%@include file="/pages/left/topmenu.jsp" %>
            
            <!--左边内容开发，开始  -->
              <div class="row wrapper border-bottom white-bg page-heading">
                <div class="col-lg-10">
                    <h2>课程表资料</h2>
                    <ol class="breadcrumb">
                        <li>
                            <a href="index.html">主页</a>
                        </li>
                        <li>
                            <a>课程表资料</a>
                        </li>
                        <li>
                            <strong>添加课程表资料</strong>
                        </li>
                    </ol>
                </div>
                <div class="col-lg-2">

                </div>
            </div>
            <div class="wrapper wrapper-content animated fadeInRight">
                
                <div class="row">
                    <div class="col-lg-14">
                        <div class="ibox float-e-margins">
                            <div class="ibox-title">
                                <h5>添加课程表资料</h5>
                                <div class="ibox-tools">
                                    <a class="collapse-link">
                                        <i class="fa fa-chevron-up"></i>
                                    </a>
                                </div>
                            </div>
                            <div class="ibox-content">
                                <form class="form-horizontal m-t" id="courselistWeeks" name="courselistWeeks" method="post" >
                                
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">地点：</label>
                                        <div class="col-sm-8">
                                            <input id="place" name="place"  maxlength="30"  class="form-control" type="text">
                                            <input id="clId" name="cl_id"  maxlength="30"  class="form-control" type="hidden">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">课程：</label>
                                        <div class="col-sm-8">
                                            <select class="form-control m-b" name="coId" id="coId">
                                            <option value="0">--请选择--</option>
                                            <c:forEach items="${requestScope.courseAll }" var="eachCourse">  
                            						<option value="${eachCourse.coId }">${eachCourse.code } - ${eachCourse.courseName }</option>
                                            </c:forEach>  
                                            </select>
                                        </div>
                                    </div>
                                    
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">教师：</label>
                                        <div class="col-sm-8">
                                            <select class="form-control m-b" name="tcId" id="tcId">
                                            <option value="0">--请选择--</option>
                                            <c:forEach items="${requestScope.teacherAll }" var="eachteacher">  
                            						<option value="${eachteacher.tcId }">${eachteacher.tcno } - ${eachteacher.tcname }</option>
                                            </c:forEach>  
                                            </select>
                                        </div>
                                    </div>
                                    
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">班级：</label>
                                        <div class="col-sm-8">
                                            <select class="form-control m-b" name="classId" id="classId">
                                            <option value="0">--请选择--</option>
                                            <c:forEach items="${requestScope.classAll }" var="eachClass">  
                            						<option value="${eachClass.classId }">${eachClass.classCode } - ${eachClass.className }</option>
                                            </c:forEach>  
                                            </select>
                                        </div>
                                    </div>
                                    
                                    
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">星期：</label>
                                        <div class="col-sm-8">
                                            <select class="form-control m-b" name="days" id="days">
                                            	<option value="0">--请选择--</option>
                                                <option value="1" >周一</option>
                                                <option value="2" >周二</option>
                                                <option value="3" >周三</option>
                                                <option value="4" >周四</option>
                                                <option value="5" >周五</option>
                                                <option value="6" >周六</option>
                                                <option value="7" >周日</option>
                                            </select>
                                        </div>
                                    </div>
                                    
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">开始节数：</label>
                                        <div class="col-sm-8">
                                            <select class="form-control m-b" id="beginClass" name="beginClass" onchange="creatEndClass(this.options[this.options.selectedIndex].value)" >
                                            	<!-- <option value="0">--请选择--</option> -->
                                                <option value="1" >第1节</option>
                                                <option value="2" >第2节</option>
                                                <option value="3" >第3节</option>
                                                <option value="4" >第4节</option>
                                                <option value="5" >第5节</option>
                                                <option value="6" >第6节</option>
                                                <option value="7" >第7节</option>
                                                <option value="8" >第8节</option>
                                                <option value="9" >第9节</option>
                                            </select>
                                        </div>
                                    </div>
                                    
                                    
                                     <div class="form-group">
                                        <label class="col-sm-3 control-label">结束节数：</label>
                                        <div class="col-sm-8">
                                            <select class="form-control m-b" id="endClass" name="endClass">
                                            	<!-- <option value="0">--请选择--</option> -->
                                                
                                            </select>
                                        </div>
                                    </div>
                                    
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">周数：</label>
                                        <div class="col-sm-8">
                                         <div data-toggle="buttons" class="btn-group" >
                                            <label class="btn btn-sm btn-white" style="width:40px;">
                                                <input type="checkbox" id="week1" name="week1" >1</label></div>
                                                <div data-toggle="buttons" class="btn-group" >
                                                 <label class="btn btn-sm btn-white" style="width:40px;">
                                                <input type="checkbox" id="week2" name="week2">2</label></div>
                                                <div data-toggle="buttons" class="btn-group" >
                                                 <label class="btn btn-sm btn-white" style="width:40px;">
                                                <input type="checkbox" id="week3" name="week3">3</label></div>
                                                <div data-toggle="buttons" class="btn-group" >
                                                 <label class="btn btn-sm btn-white" style="width:40px;">
                                                <input type="checkbox" id="week4" name="week4">4</label></div>
                                                <div data-toggle="buttons" class="btn-group" >
                                                 <label class="btn btn-sm btn-white" style="width:40px;">
                                                <input type="checkbox" id="week5" name="week5">5</label></div>
                                                <div data-toggle="buttons" class="btn-group" >
                                                 <label class="btn btn-sm btn-white" style="width:40px;">
                                                <input type="checkbox" id="week6" name="week6">6</label></div>
                                                <div data-toggle="buttons" class="btn-group" >
                                                 <label class="btn btn-sm btn-white" style="width:40px;">
                                                <input type="checkbox" id="week7" name="week7">7</label></div>
                                                <div data-toggle="buttons" class="btn-group" >
                                                 <label class="btn btn-sm btn-white" style="width:40px;">
                                                <input type="checkbox" id="week8" name="week8">8</label></div>
                                                <div data-toggle="buttons" class="btn-group" >
                                                 <label class="btn btn-sm btn-white" style="width:40px;">
                                                <input type="checkbox" id="week9" name="week9">9</label></div>
                                                <div data-toggle="buttons" class="btn-group" >
                                                 <label class="btn btn-sm btn-white" style="width:40px;">
                                                <input type="checkbox" id="week10" name="week10">10</label></div>
                                                <div data-toggle="buttons" class="btn-group" >
                                                 <label class="btn btn-sm btn-white" style="width:40px;">
                                                <input type="checkbox" id="week11" name="week11">11</label></div>
                                                <div data-toggle="buttons" class="btn-group" >
                                                 <label class="btn btn-sm btn-white" style="width:40px;">
                                                <input type="checkbox" id="week12" name="week12">12</label></div>
                                                <div data-toggle="buttons" class="btn-group" >
                                                 <label class="btn btn-sm btn-white" style="width:40px;">
                                                <input type="checkbox" id="week13" name="week13">13</label></div>
                                                <div data-toggle="buttons" class="btn-group" >
                                                 <label class="btn btn-sm btn-white" style="width:40px;">
                                                <input type="checkbox" id="week14" name="week14">14</label></div>
                                                <div data-toggle="buttons" class="btn-group" >
                                                 <label class="btn btn-sm btn-white" style="width:40px;">
                                                <input type="checkbox" id="week15" name="week15">15</label></div>
                                                <div data-toggle="buttons" class="btn-group" >
                                                 <label class="btn btn-sm btn-white" style="width:40px;">
                                                <input type="checkbox" id="week16" name="week16">16</label></div>
                                                <div data-toggle="buttons" class="btn-group" >
                                                 <label class="btn btn-sm btn-white" style="width:40px;">
                                                <input type="checkbox" id="week17" name="week17">17</label></div>
                                                <div data-toggle="buttons" class="btn-group" >
                                                <label class="btn btn-sm btn-white" style="width:40px;">
                                                <input type="checkbox" id="week18" name="week18">18</label></div>
                                                <div data-toggle="buttons" class="btn-group" >
                                                <label class="btn btn-sm btn-white" style="width:40px;">
                                                <input type="checkbox" id="week19" name="week19">19</label></div>
                                                <div data-toggle="buttons" class="btn-group" >
                                                <label class="btn btn-sm btn-white"  style="width:40px;">
                                                <input type="checkbox" id="week20" name="week20">20</label></div>
                                                <div data-toggle="buttons" class="btn-group" >
                                                <label class="btn btn-sm btn-white" style="width:40px;">
                                                <input type="checkbox" id="week21" name="week21">21</label></div>
                                                
                                        </div>
                                    </div>
                                    
                                    <div class="form-group">
                                        <div class="col-sm-8 col-sm-offset-3">
                                            <button class="btn btn-primary" id="submitbutton" onclick="checkFyFhSubmit()" type="button">提交</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
         

        </div>
    </div>
     <%@include file="/pages/head/foot.jsp" %>
    
      <!-- simditor -->

    <script>
    
        
        /** 表单验证  **/
    	function validateForm(){
    		if($("#place").val()==""){
    			alert("地点不能为空");
    			return false;
    		}
    		if($("#coId").val()==""){
    			alert("课程不可以为空");
    			return false;
    		}
    		if($("#tcId").val()==""){
    			alert("教师不可以为空");
    			return false;
    		}
    		if($("#classId").val()==""){
    			alert("班级不可以为空");
    			return false;
    		}
    		if($("#days").val()==""){
    			alert("星期不可以为空");
    			return false;
    		}
    		var weeks = "week";
    		var weekcopy ;
    		var flag = false;
    		for(var i = 1; i < 22; i++){
    			weekcopy = weeks + i;
    			if(document.getElementById(weekcopy).checked){
    				document.getElementById(weekcopy).value = "yes";
    				flag = true;
    			}else{
    				document.getElementById(weekcopy).value = "nos";
    			}
    		}
    		if(!flag){
    			alert("周数不可以为空");
    			return false;
    		}
    		
    		
    		return true;
    	}
    	
    	 function checkFyFhSubmit(){
    		 if(validateForm()){
    			 
    			 $.ajax({
    					type:"POST",
    					url:"${pageContext.request.contextPath}/courselist/addCourseList.do",
    					data:$("#courselistWeeks").serialize(),
    					async: true,
    					dataType: "text", 
    		  			error: function(request) {alert("添加信息失败！"+request.responseText);},
    					success:function(data){
    						var result=String($.trim(data));
    						if(result == "succ"){
    							alert("操作成功");
    							window.location.href="${pageContext.request.contextPath}/courselist/tosAddCourseList.do";
    						}
    						else{
    							var strs = new Array(); //定义一数组 
    							strs = result.split(","); //字符分割 
    							var a = document.getElementById('days').value;
    							var b = document.getElementById('beginClass').value;
    							var c = document.getElementById('endClass').value;
    							alert("保存失败：此班级在第" + strs[1] + "周，星期" + a + ",第" + b + "节至第" + c + "节有课，不可以重复时间！");
    						}
    						
    					}
    				});
    			 
    		 }
    		
    	} 
    	 
    	 function creatEndClass(value){
    		 var selectvalue = "" ;
    		 var j ;
    		 for(var i=value; i<10; i++){
    			 
    			 selectvalue = selectvalue + "<option value=\"" + i + "\">第" + i + "节</option>";
    		 }
    		 document.getElementById("endClass").innerHTML = selectvalue; 
    	 }
    </script>
  </body>
</html>
